/**
 * 注册qiankun子应用
 */
import {
  registerMicroApps,
  runAfterFirstMounted,
  start,
  addGlobalUncaughtErrorHandler,
  // setDefaultMountApp
} from "qiankun";

/**
 * 启动qiankun微前端应用
 */
/**
 * 全局异常捕获
 */
addGlobalUncaughtErrorHandler(event => console.log(event));
/**
 *
 * @param {Array<Object>} list 子应用路由表
 */
const userQianKun = (list) => {
  /**
 * Step2 注册子应用
 */

  /**
   * 注册子应用
   * 此处可以优化，根据权限只注册对应的子应用
   */
  registerMicroApps(list, {
    beforeLoad: [
      app => {
        console.log("[LifeCycle] before load %c%s", "color: green;", app.name);
      }
    ],
    beforeMount: [
      app => {
        console.log("[LifeCycle] before mount %c%s", "color: green;", app.name);
      }
    ],
    afterMount: [
      app => {
        console.log("[LifeCycle] after mount %c%s", "color: green;", app.name);
      }
    ],
    afterUnmount: [
      app => {
        console.log("[LifeCycle] after unmount %c%s", "color: green;", app.name);
      }
    ]
  });



  /**
   * Step3 设置默认进入的子应用
   * 如果设置的话，会出现子应用刷新路由的情况下，再去点击主应用路由url地址不对的bug
   */
  // setDefaultMountApp();

  /**
   * Step4 启动应用
   */
  start({
    prefetch: 'all'
  });

  runAfterFirstMounted(() => {
    console.log("[MainApp] first app mounted");
  });
}

export default userQianKun


